import { Module } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { TypeOrmModule } from '@nestjs/typeorm';

@Module({
  imports: [
    TypeOrmModule.forRootAsync({
      inject: [ConfigService],
      useFactory: (configService: ConfigService) => {
        return {
          type: 'mysql',
          host: configService.get('db.host'),
          port: configService.get('db.port'),
          username: configService.get('db.username'),
          password: configService.get('db.password'),
          database: configService.get('db.name'),
          // synchronize: configService.get('app.isDev'),
          synchronize: true,
          // logging: configService.get('app.isDev'),
          entities: [__dirname + '/../../**/*.entity{.ts,.js}'],
          subscribers: [__dirname + '/../**/*.subscriber{.ts,.js}'],
          connectorPackage: 'mysql2',
        };
      },
    }),
  ],
  providers: [],
})
export class DatabaseModule {}
